package com.neuedu.util;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class School {
    public static void main(String[] args) {
        try {
            String str = FileUtils.readFileToString(new File("d:/school.json"), StandardCharsets.UTF_8);
            JSONArray array = JSON.parseArray(str);
            StringBuilder builder = new StringBuilder();
            JSONArray jsonArray = new JSONArray();
            for (int i = 0; i < array.size(); i++) {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("name", array.getJSONObject(i).getString("name"));
                jsonObject.put("address", array.getJSONObject(i).getString("address"));
                jsonArray.add(jsonObject);
            }
            FileUtils.writeStringToFile(new File("d:/abcd.json"), JSON.toJSONString(jsonArray), StandardCharsets.UTF_8);

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
